package cn.cy.creation.d05;

public class Client {

    /**
     * 指挥者：项目经理
     * 抽象建造者：装修工人
     * 具体建造者：具体装修工人张三
     * 产品：客厅
     */

    public static void main(String[] args) {
        Builder builder = (Builder) ReadXML3.getInstanceByNameFromConfigFile();
        Director director = new Director(builder);
        Product product = director.construct();
        product.show();
    }

    // 1 指挥者
    static class Director {
        private Builder builder;

        Director(Builder builder) {
            this.builder = builder;
        }

        public Product construct() {
            this.builder.buildPartA();
            this.builder.buildPartB();
            this.builder.buildPartC();
            return this.builder.getResult();
        }
    }

    // 2 抽象建造者
    abstract class Builder {
        Product product = new Product();

        abstract void buildPartA();

        abstract void buildPartB();

        abstract void buildPartC();

        Product getResult() {
            return product;
        }
    }

    // 3 具体建造者
    class ConcreteBuilder extends Builder {
        @Override
        void buildPartA() {
            product.setPartA("部件A");
            System.out.println("建造者建造部件A...");
        }

        @Override
        void buildPartB() {
            product.setPartB("部件B");
            System.out.println("建造者建造部件B...");
        }

        @Override
        void buildPartC() {
            product.setPartC("部件C");
            System.out.println("建造者建造部件C...");
        }
    }

    // 4 产品
    class Product {
        private String partA;
        private String partB;
        private String partC;

        public void setPartA(String partA) {
            this.partA = partA;
        }

        public void setPartB(String partB) {
            this.partB = partB;
        }

        public void setPartC(String partC) {
            this.partC = partC;
        }

        public void show() {
            System.out.println("产品组成显示：" + this.partA + "、" + this.partB + "、" + this.partC);
        }
    }

}
